"使用成员运算符(in和not in)来判断键是否在字典中"
stu_dict = {"name":"Nun", "grade":"大三", "stu_id":"20240616","age":"20"}
if "name" in stu_dict  :
    print("Yes,stu_id")
else :
    print("No,stu_id")

""""
修改，添加，删除字典
"""

"修改字典"
print(stu_dict["age"])
"通过键来修改对应的值"
stu_dict["age"] = "21"
print(stu_dict["age"])

"添加"
stu_dict["OK"] = "11"
print("OK:",stu_dict["OK"])
"使用setdefault()来进行添加，当有对应的键时不会修改当前内容"
print(stu_dict)
stu_dict.setdefault("NOK","12")
print(stu_dict)
"当有对应的键时，不修改当前的值"
print("NOK:",stu_dict["NOK"])
stu_dict.setdefault("NOK","21")
print("NOK:",stu_dict["NOK"])

"删除"
"使用del语句删除对应的键值"
print(stu_dict)
del stu_dict["NOK"]
del stu_dict["OK"]
print(stu_dict)